"""
/* Copyright 2018 The Enflame Tech Company. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
"""
# !/usr/bin/python
# coding=utf-8

from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

from google.protobuf import json_format
import json
import uuid
from utils.dtu_logger import LOGGER as logger
import numpy as np
import math


def get_uuid():
    return uuid.uuid4().hex


def json_report(dict_file):
    json_file = json.dumps(dict_file, indent=4, sort_keys=False)
    logger.info("Test report:\n{}".format(json_file))


def export_graph_to_file(graph, graph_path):
    graph_def = graph.as_graph_def(add_shapes=True)
    json_string = json_format.MessageToJson(graph_def)
    with open(graph_path, "w") as out_file:
        out_file.write(json_string)


def check_valid_data(data):
    return np.any(np.isnan(data)) or math.isnan(data) or math.isinf(data)


def calc_inference_accuracy(predicts, real_labels):
    assert len(predicts) == len(real_labels), 'length of predict labels not equal to real ones'
    tmp_score = 0
    for index in range(len(predicts)):
        if predicts[index] == real_labels[index]:
            tmp_score += 1
    score = tmp_score / len(predicts)
    return score




if __name__ == '__main__':
    base_dict = {'a': 111,
                 'b': 222}
    json_report(base_dict)
